torque.bars['bottom.comments.tbar'] = new Ext.Toolbar({
    items: [
        new Ext.Button({
            text: 'Add',
            iconCls: 'icon-generic-add',
            handler: function() { 
                if(torque.torrents.activeHash == null) {
                    Ext.Msg.alert('No Selection', 'Please select a torrent first');
                }else{
                    Ext.Msg.prompt('Comments', 'Please enter your comment:', function(btn, text){
                        if (btn == 'ok'){
                            var conn = new Ext.data.Connection();
                            conn.request({
                                url: '/api/json/comments/add',
                                method: 'GET',
                                params: {"hash": torque.torrents.activeHash, "comment": text},
                                success: function(responseObject) {
                                    var obj = Ext.decode(responseObject.responseText);
                                    console.dir(obj);
                                    if(obj.success !== undefined) {
                                        torque.panel('torrents.comments').getStore().reload();
                                    }else if(obj.error !== undefined) {
                                        Ext.Msg.alert('Error',obj.error);
                                    }                                 
                                },
                                failure: function() {
                                    Ext.Msg.alert('Status', 'Unable to show history at this time. Please try again later.');
                                }
                            });
                        }
                    });
                }               
            }
        }),
        new Ext.Button({
            text: 'Delete',
            iconCls: 'icon-generic-delete',
            disabled: true,
            handler: function() { 
                var conn = new Ext.data.Connection();
                conn.request({
                    url: '/api/json/comments/delete/'+torque.comments.activeId,
                    method: 'GET',
                    success: function(responseObject) {
                        var obj = Ext.decode(responseObject.responseText);
                        if(obj.success !== undefined) {
                            torque.panel('torrents.comments').getStore().reload();
                        }else if(obj.error !== undefined) {
                            Ext.Msg.alert('Error',obj.error);
                        }
                    },
                    failure: function() {
                        Ext.Msg.alert('Error','Could not delete comment.');
                    }
                });
            }
        })
    ]
})
